﻿@using EasyCourse.Model;
@{
    Layout = null;
    IList<CourseInfo> lstCourseInfo = CourseInfoManage.Instance.GetAll();
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>共享资源增加</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav2.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">康复治疗微课程网络学习平台<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    <div class="container-fluid yue-nav mb15">
        <div class="container">
            <div class="row">
                <ul>
                    <li><a target="_blank" href='@Url.Action("Index","Home")'>课程群首页</a></li>
                    <li><a href="@Url.Action("MyList","Discussion")">论坛讨论</a></li>
                    <li><a class="current" href="javascript:void(0);">资源管理</a></li>
                    <li><a href="@Url.Action("StudentPersonalInfo", "UserInfo")">个人信息</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="@Url.Action("List", "StudentResManage")"><span class="glyphicon glyphicon-globe"></span> 资源共享管理</a></li>
                        <li role="presentation" class="divider"></li>
                        <li class="active" role="presentation"><a role="menuitem" tabindex="-1" href="javascript:void(0)"><span class="glyphicon glyphicon-plus"></span> 新增共享资源</a></li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>资源管理</li>
                                <li class="active">共享资源增加</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body" style="height:400px;">
                        <div class="row">
                            <form role="form" class="form-horizontal">
                                <div class="form-group clearfix">
                                    <label for="course" class="col-xs-2 control-label">课程选择：</label>
                                    <div class="col-xs-4">
                                        <select class="form-control" id="course">
                                            @for (int i = 0; i < lstCourseInfo.Count; i++)
                                            {
                                                var item = lstCourseInfo[i];
                                                if (i==0)
                                                {
                                                       <option selected="selected" value="@item.Id">@item.CourseName</option>
                                                }
                                                else
                                                {
                                                      <option value="@item.Id">@item.CourseName</option>
                                                }
                                            }
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="resTitle" class="col-xs-2 control-label">共享资源标题：</label>
                                    <div class="col-xs-4">
                                        <input type="text" class="form-control input-md" id="resTitle" placeholder="请输入资源标题">
                                    </div>
                                </div>
                                <div class="form-group clearfix">
                                    <label for="JfileName" class="col-xs-2 control-label">共享资源附件：</label>
                                    <div class="col-xs-4">
                                        <input name="fileName" id="JfileName" class="form-control mb10" readonly="readonly" />                                            
                                        <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">
                                    </div>
                                </div> 
                                <div class="form-group clearfix">
                                    <div class="col-xs-offset-2 col-xs-10">
                                        <button type="button" class="btn btn-success" id="subBtn">保存</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml");
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml");
    <script type="text/javascript" src="../Content/uploadify/jquery.uploadify.min.js?v=@DateTime.Now.Ticks"></script>
    <link href="../Css/uploadify.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            //上传文件
            var _attachmentUrl = null;
            $("#file_upload").uploadify({
                'queueSizeLimit': 1,
                //fileType代表文件类型的值可能有:   Image 、 OtherFile 、 Temp
                'formData': { 'fileType': 'OtherFile' },
                'buttonText': '请选择上传文件',
                'swf': '../Content/uploadify/uploadify.swf',
                'uploader': '@Url.Action("UpLoad", "Base")',
                'onUploadSuccess': function (file, data, response) {
                    var json = $.parseJSON(data);
                    if (json.result) {
                        _attachmentUrl = json.message; //文件保存的地址
                        $("#JfileName").val(file.name);
                        $("#JfileName").attr("data-fileUrl", _attachmentUrl);
                    }
                    else {
                        showTips.open(json.message);
                    }
                }

            });

            $("#subBtn").bind("click", function () {
                var _courseId = $("#course").val(),
                    _title = $("#resTitle").val().trim(),
                    JfileName = $("#JfileName").val(),
                    Jfile = $("#JfileName").attr("data-fileUrl");
                    $.easyPost("@Url.Action("AddResource", "StudentResManage")", { "CourseId": _courseId, "Title": _title, "FileName": JfileName, "FilePath": Jfile, "CourseId": _courseId }, function (data) {
                    if (!data.result) { showTips.open(data.message); return; }
                    else {
                        showTips.open("添加成功!");
                        //提交成功后清空所有填写数据
                        $("#resTitle").val("");
                        $("#JfileName").attr("data-fileUrl", null).val("");
                    }
                });
            });
        });
    </script>
</body>
</html>